﻿using Engine;
using Engine.Input;
using GameEntitySystem;
using TemplatesDatabase;

namespace Game
{
    public class ComponentGameSystem : ComponentInventoryBase, IUpdateable
    {
        public ComponentPlayer Player;

        public ButtonWidget AButton;

        public SubsystemSky subsystemSky;

        public SubsystemBodies m_subsystemBodies;

        public DynamicArray<ComponentBody> m_componentBodies = new DynamicArray<ComponentBody>();

        public ComponentPlayer componentPlayer;

        public SubsystemBlockEntities Entities;

        public ComponentOnFire componentOnFire;

        public ComponentMiner componentMiner;

        public bool flag = false;

        public bool flag2 = false;

        public bool flag3 = false;

        public bool flag4 = false;

        public SubsystemTime subsystemTime;

        public ComponentHealth componentHealth;

        public ComponentLocomotion componentLocomotion;

        public ComponentBody componentBody;

        public float m_frequency = 0.5f;

        public SubsystemGameInfo m_subsystemGameInfo;

        public ComponentCreature m_componentCreature;

        public SubsystemPlayers m_subsystemPlayers;

        public SubsystemNK m_subsystemHL;

        public SubsystemNK subsystemHL;

        UpdateOrder IUpdateable.UpdateOrder => ((IUpdateable)componentPlayer).UpdateOrder;

        public void Update(float dt)
        {
            Vector3 position = componentPlayer.ComponentBody.Position;
            float num = componentLocomotion.WalkSpeed;
            if (AButton.IsClicked || Keyboard.IsKeyDownOnce(Key.O))
            {
                componentPlayer.ComponentGui.ModalPanelWidget = new PositionWidget(componentPlayer.Entity.FindComponent<ComponentPlayer>(), m_subsystemHL);
            }
        }

        public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
        {
            Player = base.Entity.FindComponent<ComponentPlayer>();
            componentPlayer = base.Entity.FindComponent<ComponentPlayer>(throwOnError: true);
            componentMiner = base.Entity.FindComponent<ComponentMiner>(throwOnError: true);
            componentHealth = base.Entity.FindComponent<ComponentHealth>(throwOnError: true);
            componentLocomotion = base.Entity.FindComponent<ComponentLocomotion>(throwOnError: true);
            subsystemTime = base.Project.FindSubsystem<SubsystemTime>(throwOnError: true);
            m_subsystemGameInfo = base.Project.FindSubsystem<SubsystemGameInfo>(throwOnError: true);
            m_subsystemHL = base.Project.FindSubsystem<SubsystemNK>(throwOnError: true);
            m_subsystemPlayers = base.Project.FindSubsystem<SubsystemPlayers>(throwOnError: true);
            componentBody = base.Entity.FindComponent<ComponentBody>(throwOnError: true);
            m_subsystemBodies = base.Project.FindSubsystem<SubsystemBodies>(throwOnError: true);
            subsystemSky = base.Project.FindSubsystem<SubsystemSky>(throwOnError: true);
            base.Load(valuesDictionary, idToEntityMap);
            ContainerWidget guiWidget = componentPlayer.GuiWidget;
            AButton = guiWidget.Children.Find<ButtonWidget>("AButton");
        }
    }
}